class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int slow = 0;
        int res = 1000000;
        int sum = 0;
        for(int i = 0; i < nums.size(); i++)
        {
            sum += nums[i];
            while(sum >= target)
            {
                res = min(res, i-slow+1);
                sum -= nums[slow];
                slow++;
            }
        }

        return res == 1000000 ? 0 : res;
    }
};